<?php
    /**
     * Created by PhpStorm.
     * User: huangzhongwei
     * Date: 2018/10/25
     * Time: 9:27
     */

    namespace app\common\model;


    use think\Model;

    class AccountHasVoucher extends Model
    {
        protected $table = "account_has_voucher";
        protected $autoWriteTimestamp = true;


        public function getExpiredTimeAttr($value)
        {
            return date("Y-m-d", $value);
        }

        public static function getAccountVouchers($uid)
        {
            return self::with('voucher')->where(['account_id' => $uid, 'is_used' => 0])
                       ->where('expired_time', '>=', time())->select();
        }

        public function voucher()
        {
            return $this->belongsTo('Voucher', 'voucher_id');
        }


    }